package pers.qianyu.month_202012.date_20201215;

import java.util.*;

/**
 * [模糊]
 * 139. 单词拆分
 * https://leetcode-cn.com/problems/word-break/
 *
 * @author mizzle rain
 * @date 2020-12-15 17:00
 */
public class WordBreak {
    public boolean wordBreak(String s, List<String> wordDict) {
        int len = s.length();
        if (len == 0) {
            return false;
        }
        boolean[] dp = new boolean[len + 1];
        dp[0] = true;
        for (int i = 0; i < len + 1; i++) {
            for (String word : wordDict) {
                int w = word.length();
                if (i - w >= 0 && word.equals(s.substring(i - w, i))) {
                    dp[i] = dp[i] || dp[i - w];
                }
            }
        }
        return dp[len];
    }
}
